<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>PAG</title>
    <link rel="icon" href="https://pag.io/img/favicon.png" />
    <style>
      body {
        padding: 12px;
      }
      .header {
        height: 64px;
        border-bottom: 1px solid rgb(193, 193, 193);
        margin-bottom: 24px;
      }
    </style>
  </head>
  <body>
    <div class="header">
      <img src="../assets/logo.png" alt="logo" width="133" height="48" />
    </div>
    <div>
      <canvas class="canvas" id="pag"></canvas>
    </div>
    <script src="https://unpkg.com/libpag@latest/lib/libpag.min.js"></script>
    <script>
      window.onload = async () => {
        const pagUrl = '../assets/like.pag';
        // Initialize pag webassembly module.
        const PAG = await window.libpag.PAGInit();
        // Fetch pag file.
        const fileBlob = await fetch(pagUrl).then((response) => response.blob());
        const file = new window.File([fileBlob], pagUrl.replace(/(.*\/)*([^.]+)/i, '$2'));
        // Load the PAGFile from file.
        const pagFile = await PAG.PAGFile.load(file);
        // Set the width from the PAGFile.
        document.getElementById('pag').width = await pagFile.width();
        document.getElementById('pag').height = await pagFile.height();
        // Create PAGView.
        const pagView = await PAG.PAGView.init(pagFile, '#pag');
        // Set PAGView progress.
        await pagView.setProgress(0.5);
      };
    </script>
  </body>
</html>
